package com.pricy.me.adapters;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.atermenji.android.iconictextview.IconicFontDrawable;
import com.pricy.me.R;
import com.pricy.me.model.CategoryIcon;

public class CategoryChoiceAdapter extends BaseAdapter {
	
	private List<CategoryIcon> data;
    private Context context;
    
	public CategoryChoiceAdapter(Context context, List<CategoryIcon> cats) {
		this.data = cats;
		this.context = context;
	}
	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public CategoryIcon getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final CategoryIcon cat = getItem(position);
        ViewHolder holder;
        if (convertView == null) {
            LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = li.inflate(R.layout.category_choice, parent, false);
            holder = new ViewHolder();
            holder.title = (TextView) convertView.findViewById(R.id.cat_title);
            holder.icon = convertView.findViewById(R.id.cat_icon);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        
        holder.title.setText(cat.getTitle());
        
        
        holder.title.setTag(cat);
        
        IconicFontDrawable iconicFontDrawable = new IconicFontDrawable(context);
        iconicFontDrawable.setIcon(cat.getIcon());
        iconicFontDrawable.setIconColor(Color.BLACK);
        int sdk = android.os.Build.VERSION.SDK_INT;
        holder.icon.setBackgroundDrawable(iconicFontDrawable);
        
        return convertView;
	}
	private class ViewHolder {
        
        public TextView title;
        public View icon;
        
    }

}
